package com.baizhi.service.impl;

import com.baizhi.dao.UserDao;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public User findById(String id) {
        return userDao.findById(id);
    }

    @Override
    public boolean save(User user) {
        user.setId(UUID.randomUUID().toString());
        int result = userDao.save(user);
        return result > 0 ? true : false;
    }

    @Override
    public boolean update(User user) {
        int result = userDao.update(user);
        return result > 0 ? true : false;
    }

    @Override
    public boolean deleteById(String id) {
        int result = userDao.deleteById(id);
        return result > 0 ? true : false;
    }
}
